package com.beauty.product.dto;

import com.beauty.product.entity.ProductImage;
import jakarta.validation.constraints.NotBlank;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class ProductImageDto {
    
    private Long id;
    
    private String productId;
    
    @NotBlank(message = "图片URL不能为空")
    private String imageUrl;
    
    private Integer sort = 0;
    
    private boolean main = false;
    
    public static ProductImageDto fromEntity(ProductImage image) {
        ProductImageDto dto = new ProductImageDto();
        dto.setId(image.getId());
        dto.setProductId(image.getProductId());
        dto.setImageUrl(image.getImageUrl());
        dto.setSort(image.getSort());
        dto.setMain(image.getIsMain());
        return dto;
    }
    
    public ProductImage toEntity() {
        ProductImage image = new ProductImage();
        image.setId(this.id);
        image.setProductId(this.productId);
        image.setUrl(this.imageUrl);
        image.setImageUrl(this.imageUrl);
        image.setSort(this.sort);
        image.setIsCover(this.main);
        image.setIsMain(this.main);
        return image;
    }
} 